<?php

require_once('request/AbstractRequest.class.php');

class UserLoginRequest extends AbstractRequest {
	
	private $_out = '';
	
	/**
	 * Core fetch method.
	 *
	 * @param SimpleXML $requestXml
	 */
	protected final function internalExecute($requestXml) {
		if($requestXml == null) {
			#throw new Exception("Insufficient post data!");
			
			$xml_data = '<Request><UserCredentials><Username><![CDATA[test]]></Username><Password><![CDATA[098f6bcd4621d373cade4e832627b4f6]]></Password></UserCredentials></Request>';
			$requestXml = simplexml_load_string($xml_data);
		}
		
		$credentials = $requestXml->UserCredentials;
		
		$loginUserId = $this->userDao->validateUser($credentials->Username, $credentials->Password);
	
		if($loginUserId != -1) {
			setLoggedIn(true);
		}
		
		$this->out('<Result>');
		$this->out('<UserId>' . $loginUserId . '</UserId>');
		$this->out('</Result>');
		
		echo $this->_out;
	}
	
	private function out($text) {
		$this->_out .= $text . "\n";
	}
	
}

?>